package com.bage.finance.admin.api.controller;

import com.bage.wx.aes.AesException;
import com.bage.wx.dto.MpCommonRequest;
import com.bage.wx.service.WxMpEventService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Slf4j
@Api(tags = "微信模块")
@RestController
@RequestMapping(value = "/wxEvent")
@RequiredArgsConstructor
public class WxEventController {

    final WxMpEventService wxMpEventService;

    @ApiOperation(value = "接收微信公众号推送事件")
    @RequestMapping(value = "/receiveMpEvent", method = {RequestMethod.GET, RequestMethod.POST})
    public String receiveMpEvent(@Validated @ModelAttribute MpCommonRequest mpCommonRequest, HttpServletRequest httpServletRequest) throws AesException, IOException {
        return wxMpEventService.receiveMpEvent(mpCommonRequest, httpServletRequest);
    }
}
